// 电梯监控相关API服务

export interface ElevatorInfo {
  productName: string;
  model: string;
  location: string;
  ratedLoad: number;
  ratedSpeed: number;
  floors: number;
}

export interface OperationData {
  runCount: number;
  runTime: number;
  runDistance: number;
  stopCount: number;
  stopTime: number;
  doorCount: number;
}

export interface RealTimeData {
  updateTime: string;
  currentFloor: number;
  direction: 'up' | 'down' | 'idle';
  doorStatus: 'open' | 'closed';
  load: number;
  speed: number;
  mode: string;
}

export interface AlarmRecord {
  key: string;
  faultTime: string;
  faultName: string;
  faultFloor: number;
  faultStatus: 'pending' | 'processed';
}

// 模拟获取电梯基本信息
export const getElevatorInfo = (): Promise<ElevatorInfo> => {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve({
        productName: 'KONE E MonoSpace® DX 无机房乘客电梯',
        model: 'KONE MonoSpace / PW10/10-19',
        location: '江苏省/南京市/建邺区/南苑街道',
        ratedLoad: 800,
        ratedSpeed: 1.0,
        floors: 10,
      });
    }, 500);
  });
};

// 模拟获取运行数据
export const getOperationData = (isToday: boolean): Promise<OperationData> => {
  return new Promise((resolve) => {
    setTimeout(() => {
      if (isToday) {
        resolve({
          runCount: 25,
          runTime: 0.5,
          runDistance: 2257.3,
          stopCount: 125,
          stopTime: 10.5,
          doorCount: 125,
        });
      } else {
        resolve({
          runCount: 1250,
          runTime: 25.5,
          runDistance: 12573.2,
          stopCount: 625,
          stopTime: 52.5,
          doorCount: 625,
        });
      }
    }, 500);
  });
};

// 模拟获取实时数据
export const getRealTimeData = (): Promise<RealTimeData> => {
  return new Promise((resolve) => {
    setTimeout(() => {
      const now = new Date();
      const updateTime = now.toISOString().replace('T', ' ').substring(0, 19);

      resolve({
        updateTime,
        currentFloor: Math.floor(Math.random() * 10) + 1,
        direction: ['up', 'down', 'idle'][Math.floor(Math.random() * 3)] as
          | 'up'
          | 'down'
          | 'idle',
        doorStatus:
          Math.random() > 0.5 ? 'open' : ('closed' as 'open' | 'closed'),
        load: Math.floor(Math.random() * 100),
        speed: Math.random() * 1.0,
        mode: '正常',
      });
    }, 300);
  });
};

// 模拟获取告警记录
export const getAlarmRecords = (): Promise<AlarmRecord[]> => {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve([
        {
          key: '1',
          faultTime: '06-23 10:00',
          faultName: '非平层停靠',
          faultFloor: 8,
          faultStatus: 'pending',
        },
        {
          key: '2',
          faultTime: '06-23 10:00',
          faultName: '轿厢超速',
          faultFloor: 6,
          faultStatus: 'processed',
        },
        {
          key: '3',
          faultTime: '06-23 10:00',
          faultName: '轿厢超速',
          faultFloor: -1,
          faultStatus: 'processed',
        },
        {
          key: '4',
          faultTime: '06-23 10:00',
          faultName: '轿厢超速',
          faultFloor: 2,
          faultStatus: 'processed',
        },
        {
          key: '5',
          faultTime: '06-23 10:00',
          faultName: '轿厢超速',
          faultFloor: 3,
          faultStatus: 'processed',
        },

        {
          key: '5',
          faultTime: '06-23 10:00',
          faultName: '轿厢超速',
          faultFloor: 3,
          faultStatus: 'processed',
        },
        {
          key: '5',
          faultTime: '06-23 10:00',
          faultName: '轿厢超速',
          faultFloor: 3,
          faultStatus: 'processed',
        },
      ]);
    }, 500);
  });
};

// 模拟获取告警统计
export const getAlarmSummary = (): Promise<{
  total: number;
  processed: number;
}> => {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve({
        total: 5,
        processed: 4,
      });
    }, 300);
  });
};
